//UI初始化
layui.use(['element', 'form'], function () {
    $("#saveBtn").on("click", save);
});
var save = function () {
    var array = [];
    $("div[id^='field_']").each(function (index, obj) {
        var $obj = $(obj);
        var id = $obj.data("id");
        var ignoreEx = $("input[name='ignoreEx']", $obj).prop("checked") ? "0" : "1";
        var field = $("input[name='field']", $obj).val();
        var nameEx = $("input[name='nameEx']", $obj).val();
        var fieldType = $("input[name='fieldType']", $obj).val();
        var validateRule = $("select[name='validateRule']", $obj).val();
        var required = $("input[name='required']", $obj).prop("checked") ? "1" : "0";
        var item = {
            id: id,
            ignoreEx: ignoreEx,
            field: field,
            nameEx: nameEx,
            fieldType: fieldType,
            validateRule: validateRule,
            required: required
        };
        array.push(item);
    });
    $.ajax({
        url: "/entity/save",
        dataType: "json",
        contentType: "application/json",
        method: "POST",
        data: JSON.stringify({
            sysEntityFields:array,
            entityId: $("input[name='entityId']").val(),
            module: $("input[name='module']").val()
        }),
        success: function (result) {
            layui.use('layer', function(){
                var layer = layui.layer;

                layer.msg(result.msg);
            });
        }
    });
};

